# Docker Build Script (PowerShell Version)
param(
    [string]$Tag = "latest",
    [string]$ImageName = "nest-base",
    [switch]$Dev,
    [switch]$Help
)

# Color definitions
$Red = "Red"
$Green = "Green"
$Yellow = "Yellow"

# Print colored messages
function Write-Info {
    param([string]$Message)
    Write-Host "[INFO] $Message" -ForegroundColor $Green
}

function Write-Warning {
    param([string]$Message)
    Write-Host "[WARNING] $Message" -ForegroundColor $Yellow
}

function Write-Error {
    param([string]$Message)
    Write-Host "[ERROR] $Message" -ForegroundColor $Red
}

# Show help information
if ($Help) {
    Write-Host "Usage: .\docker-build.ps1 [options]"
    Write-Host "Options:"
    Write-Host "  -Tag TAG        Image tag (default: latest)"
    Write-Host "  -ImageName NAME  Image name (default: nest-base)"
    Write-Host "  -Dev            Build development environment image"
    Write-Host "  -Help           Show help information"
    exit 0
}

# Set build type
$BuildType = if ($Dev) { "development" } else { "production" }

Write-Info "Starting Docker image build..."
Write-Info "Image name: $ImageName"
Write-Info "Tag: $Tag"
Write-Info "Build type: $BuildType"

# Check if Docker is running
try {
    docker info | Out-Null
} catch {
    Write-Error "Docker is not running, please start Docker Desktop"
    exit 1
}

# Build image
try {
    if ($Dev) {
        Write-Info "Building development environment image..."
        docker build -t "${ImageName}:${Tag}-dev" .
    } else {
        Write-Info "Building production environment image..."
        docker build -t "${ImageName}:${Tag}" .
    }
    
    if ($LASTEXITCODE -eq 0) {
        Write-Info "Image build successful!"
        $ImageId = docker images -q "${ImageName}:${Tag}"
        Write-Info "Image ID: $ImageId"
        
        # Show image information
        Write-Host ""
        Write-Info "Image information:"
        docker images "${ImageName}:${Tag}"
    } else {
        Write-Error "Image build failed!"
        exit 1
    }
} catch {
    Write-Error "Error occurred during build process: $_"
    exit 1
} 